﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using htmlHelpers.Brand;
using htmlHelpers.Button;
using htmlHelpers.ButtonGroup;
using htmlHelpers.DropDown;
using htmlHelpers.Field;
using htmlHelpers.Html;
using htmlHelpers.Layout;
using htmlHelpers.Link;
using htmlHelpers.Menu;
using htmlHelpers.Navigation;
using htmlHelpers.Panel;
using htmlHelpers.SideBar;

namespace htmlHelpers.Extensions
{
    public class SushiFactory<TModel>
    {
        public ViewContext viewContext { get; private set; }

        /// <summary>
        /// Helper that generates a new Button
        /// </summary>
        /// <param name="id">Id property of your html client control</param>
        /// <returns><c>SushiButton</c> with the information of your control</returns>
        public SushiButtonBuilder Button()
        {
            var btn = new SushiButtonBuilder(viewContext);
            return btn;
        }

         /// <summary>
        /// Helper that generates a new SideBar
        /// </summary>
        /// <param name="id">Id property of your html client control</param>
        /// <returns></returns>
        public SushiSideBarBuilder SideBar()
        {
            var sd = new SushiSideBarBuilder(viewContext);
            return sd;
        }

        /// <summary>
        /// Helper that generates a new Panel
        /// </summary>
        /// <returns></returns>
        public SushiPanelBuilder Panel()
        {
            var pn = new SushiPanelBuilder(viewContext);
            return pn;
        }

        public SushiLayoutBuilder Layout()
        {
            var ly = new SushiLayoutBuilder(viewContext);
            return ly;
        }
        
        
        public SushiButtonGroupBuilder ButtonGroup()
        {
            var bg = new SushiButtonGroupBuilder(viewContext);
            return bg;
        }
        

        public SushiLinkBuilder Link()
        {
            var mnu = new SushiLinkBuilder(this.viewContext);
            return mnu;
        }

        public SushiNavigationBuilder Navigation()
        {
            var mnu = new SushiNavigationBuilder(this.viewContext);
            return mnu;
        }

        public SushiBrandBuilder Brand()
        {
            var brand = new SushiBrandBuilder(this.viewContext);
            return brand;
        }

        public SushiNavigationItemBuilder NavigationItem()
        {
            var mnu = new SushiNavigationItemBuilder(this.viewContext);
            return mnu;
        }

        public SushiNavigationItemHeaderBuilder NavigationItemHeader()
        {
            var mnu = new SushiNavigationItemHeaderBuilder(this.viewContext);
            return mnu;
        }

        public SushiNavigationDropDownItemBuilder NavigationDropDown()
        {
            var mnu = new SushiNavigationDropDownItemBuilder(viewContext);
            return mnu;
        }

        public SushiDropDownBuilder DropDown()
        {
            var ddp = new SushiDropDownBuilder(viewContext);
            return ddp;
        }

        public SushiFieldBuilder Field<TProperty>(Expression<Func<TModel, TProperty>> expression)
        {
            ModelMetadata modelMetadata = ModelMetadata.FromLambdaExpression<TModel, TProperty>(expression, new ViewDataDictionary <TModel>());
            var fld = new SushiFieldBuilder(viewContext);
            if (modelMetadata.IsReadOnly)
            {
                //fld.setReadOnly();
            }
            fld.SetLabelValue(modelMetadata.PropertyName);
            fld.SetInputId(modelMetadata.DisplayName + "." + modelMetadata.PropertyName);
            fld.SetInputValue(modelMetadata.PropertyName);
            return fld;
        }

        public SushiMenuBuilder Menu()
        {
            var mnu = new SushiMenuBuilder(this.viewContext);
            return mnu;
        }

        public SushiSearchBoxBuilder MenuSearchBoxItem()
        {
            var mnu = new SushiSearchBoxBuilder(this.viewContext);
            return mnu;
        }

        public SushiFactory(ViewContext view)
        {
          viewContext = view;
        }
    }

    public class SushiFactory
    {
        public ViewContext viewContext { get; private set; }

        /// <summary>
        /// Helper that generates a new Button
        /// </summary>
        /// <param name="id">Id property of your html client control</param>
        /// <returns><c>SushiButton</c> with the information of your control</returns>
        public SushiButtonBuilder Button()
        {
            var btn = new SushiButtonBuilder(viewContext);
            return btn;
        }

        /// <summary>
        /// Helper that generates a new SideBar
        /// </summary>
        /// <param name="id">Id property of your html client control</param>
        /// <returns></returns>
        public SushiSideBarBuilder SideBar()
        {
            var sd = new SushiSideBarBuilder(viewContext);
            return sd;
        }

        /// <summary>
        /// Helper that generates a new Panel
        /// </summary>
        /// <returns></returns>
        public SushiPanelBuilder Panel()
        {
            var pn = new SushiPanelBuilder(viewContext);
            return pn;
        }

        public SushiLayoutBuilder Layout()
        {
            var ly = new SushiLayoutBuilder(viewContext);
            return ly;
        }

        public SushiMenuBuilder Menu()
        {
            var mnu = new SushiMenuBuilder(this.viewContext);
            return mnu;
        }

        public SushiLinkBuilder MenuItem()
        {
            var mnu = new SushiLinkBuilder(this.viewContext);
            return mnu;
        }

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="helper"></param>
        public SushiFactory(ViewContext view )
        {
        this.viewContext = view;
        }
    }

}
